// pages/user/user.js
const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    havebind:true,
    tel:"",
    id:"",
    xiaoshou:""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  onShow:function(){
    var that = this
    that.setData({
      id:wx.getStorageSync("user_id")
    })
    // 手机绑定
    if (wx.getStorageSync('customerid') == '' || wx.getStorageSync('customerid') == 0) {
      that.setData({
        havebind:true
      })
    }else{
      that.setData({
        havebind: false
      })
    }
    wx.request({
      url: app.urlData.getURL + '/index.php/weshop/SApi/index/key/' + app.urlData.key + '/m/getPhoneNum/wid/' + app.urlData.wid + '/sign/' + wx.getStorageSync('sign'),
      method: 'get',
      success: function (res) {
        that.setData({
          tel:res.data.data.telePhone,
          xiaoshou:res.data.data.is_salesman
        })
      }
    })
   
  },     
  poster(e){
    wx.navigateTo({
      url: '/pages/poster/poster',
    })
  },
  phoneBinding(){
    wx.navigateTo({
      url: '/pages/phoneBinding/phoneBinding',
    })
  },       
  phoneHotLine(){
    if (this.data.tel == "" || this.data.tel == null){
      wx.showToast({
        title: '暂无热线',
        icon:"none",
        duration:1600
      })
      return false
    }
    console.log(this.data.tel)
    let a = this.data.tel.toString()
    wx.makePhoneCall({
      phoneNumber: a //仅为示例，并非真实的电话号码
    })
  },       
  questionFeedback(e){
    wx.navigateTo({
      url: '/pages/questionFeedback/questionFeedback',
    })
  },   
  focusOnUs(e){
    wx.navigateTo({
      url: '/pages/focusOnUs/focusOnUs',
    })
  },         

  userOrder:function(e){
    if (e.detail.errMsg == "getUserInfo:ok") {
      app.getUserInfo(wx.getStorageSync('sign'), e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl, e.detail.userInfo.gender, e.detail.encryptedData, e.detail.iv)
      wx.navigateTo({
        url: '/pages/userOrder/userOrder?tab=' + e.currentTarget.dataset.tab,
      })
    } else if (e.detail.errMsg == "getUserInfo:fail auth deny") {
      wx.showToast({
        title: '抱歉，拒绝授权将无法查询订单',
        icon: 'none',
        duration: 2500
      })
    }
  },
  onShareAppMessage: function (res) {
    return {
      title: "PAPARELA  我的御用化妆师",
    }
  },
})